<%= append_javascript_pack_tag "decidim_elections_admin" %>

<div class="item_show__header form-defaults border-none">
  <h1 class="item_show__header-title">
    <%= t("decidim.elections.actions.edit") %>
  </h1>
</div>

<%= render "decidim/elections/admin/elections/tabs_menu" %>

<div class="form-defaults my-8 flex justify-end">
  <%= select_tag "census_manifest",
                 options_for_select(census_manifests.to_h { |manifest| [manifest.label, manifest.name] }, selected: election.census&.name),
                 include_blank: t(".choose_census"),
                 id: "census-manifest-selector" %>
</div>

<% if election.census_ready? %>
    <%
      census_ready = t("decidim.elections.censuses.census_ready_html", election_title: decidim_sanitize_translated(election.title))
      census_count = t("decidim.elections.censuses.census_size_html", count: census_count(election))
    %>
    <%= cell "decidim/announcement", "#{census_ready}<br>#{census_count}", callout_class: "success" %>
<% end %>

<div class="card-section census-form form-defaults 2xl:mr-80">
  <% if @form && election.census&.admin_form_partial %>
    <%= decidim_form_for(@form, url: election_census_path(election, manifest: election.census&.name), method: :patch, multipart: true, html: { id: "census-election-form" }) do |f| %>
      <%= render partial: election.census.admin_form_partial, locals: { form: f } %>
    <% end %>
  <% end %>

  <%= render partial: "decidim/elections/admin/census/preview", locals: { election: } if preview_users(election).present? %>
</div>

<div class="item__edit-sticky">
  <div class="item__edit-sticky-container">
    <%= button_tag t("save", scope: "decidim.elections.admin.elections.form"), class: "button button__sm button__secondary #{"hide" unless election.census}", form: "census-election-form" %>
  </div>
</div>
